package com.skyolder.milkbee.service;

import com.skyolder.milkbee.domain.Questionnaire;
import com.skyolder.milkbee.dto.Vote;
import com.skyolder.milkbee.repository.QuestionnaireRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
 * Service Implementation for managing Questionnaire.
 */
@Service
@Transactional
public class QuestionnaireService {

    private final Logger log = LoggerFactory.getLogger(QuestionnaireService.class);
    
    @Inject
    private QuestionnaireRepository questionnaireRepository;

    /**
     * Save a questionnaire.
     *
     * @param questionnaire the entity to save
     * @return the persisted entity
     */
    public Questionnaire save(Questionnaire questionnaire) {
        log.debug("Request to save Questionnaire : {}", questionnaire);
        Questionnaire result = questionnaireRepository.save(questionnaire);
        return result;
    }

    /**
     *  Get all the questionnaires.
     *  
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true) 
    public Page<Questionnaire> findAll(Pageable pageable) {
        log.debug("Request to get all Questionnaires");
        Page<Questionnaire> result = questionnaireRepository.findAll(pageable);
        return result;
    }

    /**
     *  Get one questionnaire by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true) 
    public Questionnaire findOne(Long id) {
        log.debug("Request to get Questionnaire : {}", id);
        Questionnaire questionnaire = questionnaireRepository.findOne(id);
        return questionnaire;
    }

    /**
     *  Delete the  questionnaire by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Questionnaire : {}", id);
        questionnaireRepository.delete(id);
    }

	

	public Vote findOneVote(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public Page<Questionnaire> findByUserId(Long userId, Pageable pageable) {
		// TODO Auto-generated method stub
		return questionnaireRepository.findByUserId(userId,pageable);
	}

	public Page<Questionnaire> findByCategoryId(Long categoryId, Pageable pageable) {
		// TODO Auto-generated method stub
		return questionnaireRepository.findByCategoryId(categoryId,pageable);
	}
}
